package com.alibaba.citrus.cr.common.enums;

import java.util.Arrays;
import java.util.Objects;

public enum GeneralStatusEnum {
    NO(0, "否"),
    YES(1, "是"),
    ;
    private Integer code;
    private String desc;

    GeneralStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static GeneralStatusEnum of(Integer code) {
        return Arrays.stream(GeneralStatusEnum.values()).filter(source -> Objects.equals(code, source.getCode())).findFirst().orElse(null);
    }

    public static String descByCode(Integer code) {
        GeneralStatusEnum typeEnum = of(code);
        return Objects.nonNull(typeEnum) ? typeEnum.getDesc() : "未知";
    }
}
